package com.guoqing.utils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zhangguoqing
 * @date 2020/9/25
 * Description: TODO
 */
public class MapUtil {
    /**
     * 根据 key 排序，升序
     *
     * @param map 入参
     * @param <K> key
     * @param <V> value
     * @return map
     */
    public static <K extends Comparable<? super K>, V> Map<K, V> sortMap(Map<K, V> map) {
        Map<K, V> linkedHashMap = new LinkedHashMap<>();
        map.entrySet().stream().sorted(Map.Entry.<K, V>comparingByKey().reversed())
                .forEachOrdered(e -> linkedHashMap.put(e.getKey(), e.getValue()));
        return linkedHashMap;
    }
}
